// 获取格式化时间
export function getFormatDate(date,type){
	if(!date || new Date(date) == "Invalid Date"){
		date=new Date();
	}else{
		date=new Date(date);
	};
	let MyDate=date;
	let Year=MyDate.getFullYear(); //获取年
	let Month=(MyDate.getMonth()+1)<10?"0"+(MyDate.getMonth()+1):(MyDate.getMonth()+1); //获取月
	let nativeMonth=MyDate.getMonth()+1; //获取原生月
	let Day=MyDate.getDate()<10?"0"+MyDate.getDate():MyDate.getDate(); //获取日
	let nativeDay=MyDate.getDate(); //获取原生天
	let Hour=MyDate.getHours()<10?"0"+MyDate.getHours():MyDate.getHours(); //获取小时
	let Minute=MyDate.getMinutes()<10?"0"+MyDate.getMinutes():MyDate.getMinutes(); //获取分钟
	let Second=MyDate.getSeconds()<10?"0"+MyDate.getSeconds():MyDate.getSeconds(); //获取秒钟
	let weekDay=MyDate.getDay(); //获取星期几
	let formatDate=Year+"-"+Month+"-"+Day+" "+Hour+":"+Minute+":"+Second;
    let weekArr=["日","一","二","三","四","五","六"];
	let weekDetailArr=["星期天","星期一","星期二","星期三","星期四","星期五","星期六"];
	switch (type) {
		case "yyyy" : formatDate=Year+"" ; break ;
		case "yyyy-MM" : formatDate=Year+"-"+Month ; break;
		case "yyyy-MM-dd" : formatDate=Year+"-"+Month+"-"+Day ; break;
		case "yyyy-MM-dd hh:mm" : formatDate=Year+"-"+Month+"-"+Day+" "+Hour+":"+Minute ; break;
		case "yyyy-MM-dd hh:mm:ss" : formatDate=Year+"-"+Month+"-"+Day+" "+Hour+":"+Minute+":"+Second ; break;
		case "M" : formatDate=nativeMonth+"" ; break;
		case "MM" : formatDate=Month+"" ; break;
		case "MM-dd" : formatDate=Month+"-"+Day ; break;
		case "MM-dd hh:mm" : formatDate=Month+"-"+Day+" "+Hour+":"+Minute ; break;
		case "MM-dd hh:mm:ss" : formatDate=Month+"-"+Day+" "+Hour+":"+Minute+":"+Second ; break;
		case "d" : formatDate=nativeDay+"" ; break;
		case "dd" : formatDate=Day+"" ; break;
		case "dd hh:mm" : formatDate=Day+" "+Hour+":"+Minute ; break;
		case "dd hh:mm:ss" : formatDate=Day+" "+Hour+":"+Minute+":"+Second ; break;
		case "hh:mm:ss" : formatDate=Hour+":"+Minute+":"+Second ; break;
		case "hh:mm" : formatDate=Hour+":"+Minute ; break;
		case "chinese" : formatDate=Year+"年"+Month+"月"+Day+"日" ; break;
		case "chinese hh:mm" : formatDate=Year+"年"+Month+"月"+Day+"日"+" "+Hour+":"+Minute ; break;
		case "chinese hh:mm:ss" : formatDate=Year+"年"+Month+"月"+Day+"日"+" "+Hour+":"+Minute+":"+Second ; break;
		case "week" : formatDate=weekArr[weekDay] ; break;
        case "weekDetail" : formatDate=weekDetailArr[weekDay] ; break;
	};
	return formatDate;
};

/**
 * 对象数据的深拷贝方法
 * @params source
 * @returns targetObj
 */
export function deepClone(source){
	if(!source && typeof source !== "object"){
		throw new Error("错误的参数");
	};
	const targetObj=Object.prototype.toString.call(source) === "[object Array]" ? [] : {};
	Object.keys(source).forEach((key)=>{
		if(source[key] && typeof source[key] === "object"){
			targetObj[key]=deepClone(source[key]);
		}else{
			targetObj[key]=source[key];
		};
	});
	return targetObj;
};
